package org.lpw.wormhole.util;

import java.security.MessageDigest;

import org.apache.commons.codec.binary.Hex;

/**
 * @author lpw
 */
public class SecurityImpl
    implements Security
{
    private static final String MD5 = "MD5";// MD5标记。

    private final Kit kit;

    public SecurityImpl(Kit kit)
    {
        super();

        this.kit = kit;
    }

    @Override
    public String md5(String text)
    {
        try
        {
            return text==null?null:Hex.encodeHexString(MessageDigest.getInstance(MD5).digest(text.getBytes()));
        }
        catch(Exception e)
        {
            kit.getLogger().warn(e, "获取MD5消息摘要时发生异常！");

            return null;
        }
    }
}
